var QualityAssurances = {//质量管理管理初始化
    id: "QualityAssurancesOneTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

function _cellStyles(value, row, index) {
    if (row.status == 1) {
        return {css: {"background-color": "#fff1d5", "overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    } else {
        return {css: {"overflow": "hidden", "white-space": "nowrap", "text-overflow": "ellipsis"}}
    }
}

QualityAssurances.initColumn = function () {//初始化表格的列
    return [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: 'num', field: 'num', visible: false, align: 'center', valign: 'middle'},
        {title: 'status', field: 'status', visible: false, align: 'center', valign: 'middle'},
        {
            title: '患者姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '上传时间', field: 'createTime', align: 'center', valign: 'middle', sortable: true, width: 120,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '上传人姓名', field: 'createName', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '种类', field: '', align: 'center', valign: 'middle', sortable: true, width: 70,
            formatter: function (value, row, index) {
                return "牙周";
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '门诊', field: 'arrivalStore', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '护士', field: 'nurse', align: 'center', valign: 'middle', sortable: true, width: 70,
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        },
        {
            title: '操作', field: 'operation', align: 'center', valign: 'middle', width: 60,
            formatter: function (value, row, index) {
                var ids1 = row.num + "," + row.reservationsId + "," + 1;
                var ids2 = row.num + "," + row.reservationsId + "," + 2;
                return '<button title="术前详情" onclick="QualityAssurances.openPeriodontalIconTypes(' + "'" + ids1 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button> ' +
                    '<button title="术后详情" onclick="QualityAssurances.openPeriodontalIconTypes(' + "'" + ids2 + "'" + ')" style="background: #ffffff;border: 1px solid #cccccc;padding: 1px 4px 0 5px;" type="button" class="btn"><span class="glyphicon glyphicon-eye-open"></span></button>';
            },
            cellStyle: function (value, row, index) {
                return _cellStyles(value, row, index);
            }
        }
    ];
};

//牙周术前图片回显
QualityAssurances.openPeriodontalIconTypes = function(ids) {
    var index = layer.open({
        type: 2,
        title: '牙周术前图片回显',
        area: ['80%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/qualityPeriodontalDisplay/' + ids
    });
    this.layerIndex = index;
};

QualityAssurances.check = function () { // 检查是否选中
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        QualityAssurances.seItem = selected[0];
        return true;
    }
};

QualityAssurances.search = function () {//图片质量管理查询
    QualityAssurances.table.refresh({query: QualityAssurances.formParams()});
};

QualityAssurances.getData = function () { // 片区筛选
    var params = {area: $("#area").val()};
    $.post(Feng.ctxPath + "/dept/getListByArea", params, function (data) {
        $('#arrivalStore').empty();
        $('#arrivalStore').append('<option value="">请选择</option>');
        for (var i = 0; i < data.length; i++) {
            $('#arrivalStore').append("<option value=" + data[i].simplename + ">" + data[i].simplename + "</option>");
        }
        QualityAssurances.search();
    }, "json");
};

QualityAssurances.formParams = function () {//查询质量管理列表
    var queryData = {};
    queryData['startCreateTime'] = $("#startUploadTime").val();
    queryData['endCreateTime'] = $("#endUploadTime").val();
    queryData['createName'] = $("#addName").val();
    queryData['arrivalStore'] = $("#arrivalStore").val();
    queryData['status'] = $("#status").val();
    queryData['scoreTOTAL'] = $("#scoreTOTAL").val();
    queryData['area'] = $("#area").val();
    return queryData;
};

QualityAssurances.resetSearch = function () {//重置
    $("#startUploadTime").val("");
    $("#endUploadTime").val("");
    $("#addName").val("");
    $("#arrivalStore").val("");
    $("#status").val("");
    $("#scoreTOTAL").val("");
    QualityAssurances.search();
};

QualityAssurances.time = function () {//初始化赋值时间 + 请求数据
    var outpatientName = $('#outpatientName').val();
    var areaAbbreviation = $('#areaAbbreviation').val();
    $("#area option[value='" + areaAbbreviation + "']").attr("selected", "selected");
    $("#arrivalStore option[value='" + outpatientName + "']").attr("selected", "selected");
    $("#startUploadTime").val(setDateTime(new Date(), 0) + " " + "00:00:00");
    $("#endUploadTime").val(setDateTime(new Date(), 0) + " " + "23:59:59");
    QualityAssurances.search();
};

checkDate = function () {QualityAssurances.search();};

$(function () {
    var defaultColunms = QualityAssurances.initColumn();
    var table = new BSTable(QualityAssurances.id, "/rootPeriodontal/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(QualityAssurances.formParams());
    QualityAssurances.table = table.init();
    QualityAssurances.time();
});